
using System;
using System.Data;
using System.Data.SqlClient;
using ERP_RORZE_ORDER.Common;
using ERP_RORZE_ORDER.Common.ValueObject;
using ERP_RORZE_TOOL.Common;
using ERP_RORZE_TOOL.DBAccess;

namespace ERP_RORZE_ORDER.DBAccess
{

	public class CurrencyDAO : BaseDAO
	{
        #region Basic Method

        public static DataTable GetAll()
        {
            return ExcuteProcedure(OrderConstants.StoreProcedure.Currency.GetAll);
        }

        public static DataTable GetOne(string currencyId)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
						CreateParameter("@CurrencyID", SqlDbType.NVarChar, currencyId)
                    };
                return ExcuteProcedure(OrderConstants.StoreProcedure.Currency.GetOne, parameters);

            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }

        }

        public static Currency LoadOne(string currencyId)
        {
            Currency o = new Currency();
            DataTable dt = GetOne(currencyId);
            if (dt.Rows.Count > 0)
            {
                //o.ID = int.Parse(dt.Rows[0][OrderConstants.Entities.Currency.FieldName.ID].ToString());
                o.CurrencyID = dt.Rows[0][OrderConstants.Entities.Currency.FieldName.CurrencyID].ToString();
                o.CurrencyName = dt.Rows[0][OrderConstants.Entities.Currency.FieldName.CurrencyName].ToString();

            }

            return o;
        }


        public static int Insert(Currency o)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@CurrencyID", SqlDbType.NVarChar, o.CurrencyID),
                        CreateParameter("@CurrencyName", SqlDbType.NVarChar, o.CurrencyName),
                    };

                return ExecuteNonQueryProcedure(OrderConstants.StoreProcedure.Currency.Insert, parameters);

            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }

        }

        public static int Update(Currency o)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@TempID", SqlDbType.NVarChar, o.TempId),
                        CreateParameter("@CurrencyID", SqlDbType.NVarChar, o.CurrencyID),
                        CreateParameter("@CurrencyName", SqlDbType.NVarChar, o.CurrencyName),
                    };

                return ExecuteNonQueryProcedure(OrderConstants.StoreProcedure.Currency.Update, parameters);
            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }
        }

        public static int Delete(Currency o)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@CurrencyID", SqlDbType.NVarChar, o.CurrencyID)
                    };

                return ExecuteNonQueryProcedure(OrderConstants.StoreProcedure.Currency.Delete, parameters);
            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }
        }

        public static DataTable GetTemplateTable()
        {
            DataTable table = new DataTable("243_Currency");

            return table;
        }

       
        #endregion
    }
	
}
